package com.zzyl.controller;


import com.github.pagehelper.Page;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "护理项目管理相关接口")
@RequestMapping("/nursing_project")
@RequiredArgsConstructor
public class NursingProjectController {
    private final NursingProjectService nursingProjectService;
    @GetMapping
    @ApiOperation(value = "分页查询护理项目")
    public ResponseResult selectPage(String name,Integer status,Integer pageNum,Integer pageSize){
        PageResponse<NursingProjectVo> nursingProjectVoPageResponse = nursingProjectService.selectByPage(name, status, pageNum, pageSize);
        return ResponseResult.success(nursingProjectVoPageResponse);
    }
    @PostMapping()
    @ApiOperation(value = "新增护理项目")
    public ResponseResult add(@RequestBody NursingProjectDto nursingProjectDto){
        nursingProjectService.insert(nursingProjectDto);
        return ResponseResult.success();
    }
    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查询护理项目")
    public ResponseResult selectById(@PathVariable("id") Long id){
        NursingProjectVo nursingProjectVo =nursingProjectService.selectById(id);
        return ResponseResult.success(nursingProjectVo);
    }
    @PutMapping
    @ApiOperation(value = "修改护理项目")
    public ResponseResult update(@RequestBody NursingProjectDto nursingProjectDto){
        nursingProjectService.update(nursingProjectDto);
        return ResponseResult.success();
    }
    @PutMapping("/{id}/status/{status}")
    @ApiOperation(value = "禁用启用护理项目")
    public ResponseResult startOrStop(@PathVariable Long id,@PathVariable Integer status){
        nursingProjectService.startOrStop(id,status);
        return ResponseResult.success();
    }
    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除护理项目")
    public ResponseResult deleteById(@PathVariable("id") Long id){
        nursingProjectService.deleteById(id);
        return ResponseResult.success();
    }
    @GetMapping("/all")
    @ApiOperation(value = "查询所有护理项目")
    public ResponseResult selectAll(){
        List<NursingProjectVo> nursingProjectVoList = nursingProjectService.findAll();
        return ResponseResult.success(nursingProjectVoList);
    }
}
